#!/bin/sh
### BEGIN INIT INFO
# Provides:          red5sip
# Required-Start:    networking
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
set -e
DESC="Red5Sip bridge"
NAME=red5sip
RED5SIP_HOME=/opt/red5sip
DAEMON=$RED5SIP_HOME/$NAME.sh
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

#
# Function that starts the daemon/service.
#
d_start() {
	start-stop-daemon --start -c nobody --pidfile $PIDFILE --chdir $RED5SIP_HOME --background --make-pidfile --exec $DAEMON
}
#
# Function that stops the daemon/service.
#
d_stop() {
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --name java
	rm -f $PIDFILE
}

case "$1" in
	start)
		echo -n "Starting $DESC: $NAME\n"
		d_start
	;;
	stop)
		echo -n "Stopping $DESC: $NAME\n"
		d_stop
	;;
	restart|force-reload)
		echo -n "Restarting $DESC: $NAME\n"
		d_stop
		sleep 1
		d_start
	;;
	*)
		echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
		exit 1
	;;
esac
exit 0
